/**
 * Created by levy on 16/6/15.
 */

var Person = React.createClass({
    getInitialState: function () {
        return {
            selectStatus: ''
        }
    },
    getDefaultProps: function () {
        return {
            maxCount: 1 // 默认最多能选择一个人
        }
    },
    componentDidMount: function () {
        var me = this,
            max_count = me.props.maxCount;
        React.findDOMNode(this.refs.selectItem).addEventListener('touchend', function () {
            var $this = $(this),
                $select_class = $this.parent().parent(),
                choose_item = $($select_class[0]).find('.choose');
            //人员的id在这里
            //log($this.data('id'))

            if ( max_count == 1 ) {// 单选时
                choose_item.size() && choose_item.removeClass('choose');
                $(this).addClass('choose');
                return ;
            }
            if ( choose_item.size() >= max_count && !$this.hasClass('choose') ) {
                return ;
            }

            $(this).toggleClass('choose');

        }, false);
    },
    render: function () {
        return (
            <a ref="selectItem" className='text-dot' data-id={this.props.item.id} href="javascript:">{this.props.item.name}</a>
        )
    }
});

export default Person;
